package com.qmds.patrolserver.process.service.impl;

import com.qmds.common.core.entity.PatrolProcess;
import com.qmds.common.core.entity.PatrolTickes;
import com.qmds.common.core.utils.UserUtils;
import com.qmds.common.core.vo.R;
import com.qmds.patrolserver.process.dao.PatrolProcessDao;
import com.qmds.patrolserver.process.params.ProcessParam;
import com.qmds.patrolserver.process.service.PatrolProcessService;
import com.qmds.patrolserver.tickes.dao.PatrolTickesDao;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class PatrolProcessServiceImpl implements PatrolProcessService {

    @Resource
    private PatrolProcessDao patrolProcessDao;

    @Resource
    private PatrolTickesDao patrolTickesDao;

    @Override
    public R process(ProcessParam param) {

        PatrolTickes patrolTickes = patrolTickesDao.selectById(param.getTid());
        // 看一下工单是否存在
        if (patrolTickes == null) {
            throw new RuntimeException("工单不存在");
        }
        // 获取修改人id
        if (param.getDetails() == null || param.getDetails().equals("")) {
            throw new RuntimeException("请输入处理详情");

        }
        param.setUid(2);
//        param.setUid(UserUtils.getId());
        PatrolProcess patrolProcess = new PatrolProcess();
        BeanUtils.copyProperties(param,patrolProcess);
        patrolProcess.setUpdateTime(new Date());
        Integer i = patrolProcessDao.insert(patrolProcess);
        if (i >= 0) {
            return R.ok("添加成功");
        }
        return R.fail("更新失败");
    }
}
